package jim;

/**
 * Created with IntelliJ IDEA.
 * User: Jim
 * Date: 5/29/13
 * Time: 9:34 PM
 * To change this template use File | Settings | File Templates.
 */
public class JTree {

    private JNode root;
    private JNode found;

    public JTree(JNode root) {
        this.root = root;
    }

    private void find(int value, JNode node) {
        if (node.value == value) {
            found = node;
        }
        if (node.left != null) {
            find(value, node.left);
        }
        if (node.right != null) {
            find(value, node.right);
        }
    }

    public JNode find(int value) {
        find(value, root);
        return found;
    }

    public static void main(String[] args) {
        JNode grandchild5 = new JNode(5,null,null);
        JNode grandchild4 = new JNode(4,null,null);
        JNode grandchild2 = new JNode(2,null,null);
        JNode grandchild7 = new JNode(7,null,null);
        JNode child9 = new JNode(9,grandchild5,grandchild4);
        JNode child8 = new JNode(8,grandchild2,grandchild7);
        JNode root = new JNode(8,child9,child8);

        JTree tree = new JTree(root);
        JNode found = tree.find(8);
        System.out.println(found);
    }

}
